<script>
export default {
  data() {
    return {
      searchKeyword: '',
      total:0,
      current:1,
      pageSize:5000,
      // 搜索框
      selectedInstitution:{},
      institutions: [
      ],
    }
  },
  methods: {
    searchDoctors(){
      this.axios.post(`http://localhost:8302/institution/findpage?current=${this.current}&pageSize=${this.pageSize}`,this.selectedInstitution).then(res=>{
        this.institutions=res.data.data.records
        this.total=res.data.data.total
      })
    },
    zt(form){
        if (form.status==1){
          form.status=0
          this.axios.post(`http://localhost:8302/institution/save`,form).then(res=>{
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
          })
        }else {
          form.status=1
          this.axios.post(`http://localhost:8302/institution/save`,form).then(res=>{
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
          })
        }
    },
    dc(){
      location.href = 'http://localhost:8302/institution/dc';
    },
    tj(){
      this.$router.push('/addjg')
    },
    bj(low){
      localStorage.setItem("institution",JSON.stringify(low))
      this.$router.push('/addjg')
    },
    del(low111){
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',style: 'width: 40px',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {l
        // 这里是用户点击确定后执行的代码，例如发送删除请求到后端
        low.del=0
        this.axios.post(`http://localhost:8302/institution/save`,low).then(res=>{
          this.searchDoctors();
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
  },
  created() {
    this.searchDoctors();
  }
}
</script>

<template>
  <div style="width: 100%;margin-left: 20px;margin-right: 20px" align="center;">
    <div style="background-color: #F2F7FB;padding: 10px 0px 0px 0px" >
      <el-header align="left" style="margin-top: 60px;"> |  机构管理</el-header>
      <el-main align="left">
        <el-input placeholder="请输入关键字" v-model="selectedInstitution.organization" style="width: 400px;margin-bottom: 20px"></el-input>
        <el-button type="primary" @click="searchDoctors" style="width: 100px;">搜索</el-button>

        <el-button type="primary" @click="dc" style="width: 100px;float: right">导出</el-button>
          <el-button type="primary" @click="tj" style="width: 100px;float: right">新增机构</el-button>

        <el-table :data="institutions">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="id" label="编号"></el-table-column>
          <el-table-column width="100px">
            <template slot-scope="scope">
              <img :src="scope.row.img" width="50px"></img">
            </template>
          </el-table-column>
          <el-table-column prop="organization" label="机构名称"></el-table-column>
          <el-table-column prop="principalname" label="负责人姓名"></el-table-column>
          <el-table-column prop="phone" label="电话"></el-table-column>
          <el-table-column prop="address" label="机构地址"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <a @click="zt(scope.row)">
                <el-tag v-if="scope.row.status==1" type="success">启用</el-tag>
                <el-tag v-else type="danger">禁用</el-tag>
              </a>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button style="width: 60px" @click="bj(scope.row)" type="primary" size="small">编辑</el-button>
              <el-button style="width: 60px" @click="del(scope.row)" type="danger" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </div>
  </div>
</template>

<style>
.el-message-box__btns button:nth-child(2){
  width: 100px;
}
.el-button--small{
  width: 100px;
}
</style>
